﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;

namespace YasharEl.Infrastructure.ObjectFactory
{
    [ContractClass(typeof(DependencyResolverContract))]
    public interface IDependencyResolver
    {
        TService Resolve<TService>();
        TService Resolve<TService>(string key);

        object Resolve(Type type);
        object Resolve(Type type, string key);

        IEnumerable<TService> ResolveAllInstances<TService>();

        IEnumerable<object> ResolveAllInstances(Type type);
    }

    [ContractClassFor(typeof(IDependencyResolver))]
    internal abstract class DependencyResolverContract : IDependencyResolver
    {
        public TService Resolve<TService>()
        {
            return default(TService);
        }

        public TService Resolve<TService>(string key)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(key), "Key could not be null.");

            return default(TService);
        }

        public object Resolve(Type type)
        {
            Contract.Requires<ArgumentNullException>(type != null, "Type could not be null.");

            return default(object);
        }

        public object Resolve(Type type, string key)
        {
            Contract.Requires<ArgumentNullException>(type != null, "Type could not be null.");
            Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(key), "Key could not be null.");

            return default(object);
        }

        public IEnumerable<TService> ResolveAllInstances<TService>()
        {
            return new List<TService>();
        }

        public IEnumerable<object> ResolveAllInstances(Type type)
        {
            Contract.Requires<ArgumentNullException>(type != null, "Type could not be null.");

            return new List<object>();
        }
    }
}
